﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WinPanel : MonoBehaviour
{
    public Button ContinueButton;
    public GameObject can, Voiceobj,BigLight,SmallLight;
    public Text LvText, GoldText;
    // Start is called before the first frame update
    void Start()
    {
        CloneVoice();
        GoldAndLv.instance.audio.Stop();
        can = GameObject.Find("Canvas");
        ContinueButton.onClick.AddListener(OnClickContinnueButton);
        GengXin();
    }
    /// <summary>
    /// 克隆短音效
    /// </summary>
    public void CloneVoice()
    {
        Voiceobj = Instantiate(Resources.Load<GameObject>("CloneVoice"));
        Voiceobj.transform.SetParent(gameObject.transform);
    }

    // Update is called once per frame
    void Update()
    {
        BigLight.transform.Rotate(0,0, 4);
        SmallLight.transform.Rotate(0, 0, 5);
    }
    /// <summary>
    /// 更新金币信息
    /// </summary>
    public void GengXin()
    {
        GoldText.text = (GamePanel.instance.MaxScore * 2).ToString();
        LvText.text = "LV=" + (DataManager.Instance.Lv).ToString();
    }
    public void OnClickContinnueButton()
    {
        ShortVoice.instance.PlayVoice("AnNiu");
        DestroyImmediate(gameObject);
        GameObject obj = Instantiate(Resources.Load<GameObject>("UIPanel/MainPanel"));
        obj.transform.SetParent(can.transform);
        obj.transform.localPosition = new Vector3(0, 0, 0);
        obj.transform.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
        obj.transform.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
        obj.transform.GetComponent<RectTransform>().anchorMin = Vector2.zero;
        obj.transform.GetComponent<RectTransform>().anchorMax = Vector2.one;
        GoldAndLv.instance.GengXin();
        GoldAndLv.instance.PlayVoice();
        Destroy(Voiceobj);

    }
}
